package easycloud.ecs.web.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import easycloud.ecs.common.domain.User;
import easycloud.ecs.web.exception.SessionNotFoundException;

@Controller
@RequestMapping("/")
public class IndexController extends BaseController {

	private static final Log logger = LogFactory.getLog(IndexController.class);

	@RequestMapping("home")
	public ModelAndView home(HttpServletRequest request) {
		IndexController.logger.debug("home");
		ModelAndView mav = new ModelAndView("home");
		try {
			User user = getUser(request);
			mav.addObject("user", user);
		} catch (SessionNotFoundException e) {
			mav.setViewName("redirect:/index");
		}
		return mav;
	}

	@RequestMapping("index")
	public ModelAndView index(Locale locale) {
		IndexController.logger.debug("index");
		ModelAndView mav = new ModelAndView("index");
		return mav;
	}

	@RequestMapping("")
	public ModelAndView root() {
		ModelAndView mav = new ModelAndView("index");
		return mav;
	}
}
